#include <stdio.h>
#include <sys/un.h>
#include <unistd.h>
#include "wrap.h"
int main(int argc, char const *argv[])
{
        int fd = Socket(AF_LOCAL,SOCK_STREAM,0);

        //如果套接字文件存在，删除套接字文件 否则下次启动程序会bind error: Address already in use
        unlink("client.sock");
        
        //给客户端绑定一个本地套接字文件
        struct sockaddr_un client;
        client.sun_family = AF_LOCAL;
        strcpy(client.sun_path,"client.sock");
        Bind(fd,(struct sockaddr *)&client, sizeof(client));

        //初始化server信息
        struct sockaddr_un serv;
        serv.sun_family = AF_LOCAL;
        strcpy(serv.sun_path,"server.sock");

        //连接服务器
        Connect(fd,(struct sockaddr*)&serv,sizeof(serv));

        //通讯
        char buf[1024] = {0};
        while (1){
                memset(buf,0,sizeof(buf));
                fgets(buf,sizeof(buf),stdin);
                send(fd,buf,strlen(buf)+1,0);

                //接收数据
                recv(fd,buf,sizeof(buf),0);
                printf("recv buf: %s",buf);
        }
        Close(fd);
        return 0;
}
